import { defineStore } from 'pinia';

export const useUserStore = defineStore('user', {
    state() {
        return {
            userInfo: {

            }
        }
    },
    getters: {
        token() {

        }
    },
    actions: {
        async getUserInfo() {
            try {
                const res = await api.getUser()
                const {id, name, avatar, role} = res.data
                this.userInfo = {id, name, avatar, role}
                return Promise.resolve(res.data)
            } catch (error) {
                return Promise.reject(error)
            }
        },
        async signIn() {

        },
        async signOut() {
            this.$reset()
        },
        setUserInfo(userInfo = {}) {
            this.userInfo = {...this.userInfo, ...userInfo}
        }
    }
});